using HKB.Common;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Web;
namespace HKB.Web
{
	public class Shop_MyFavourite
	{
		private Conn conn = null;
		public Shop_MyFavourite()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public Shop_MyFavourite(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable GetAllFav()
		{
			return this.conn.GetDataTable("Select * From [HLShop_MyFavourite]");
		}
		public DataTable GetFavShopByShopNameShopChildFPCUserID(string ShopName, int ShopChildID, int F_ShopClassID, int F_UserID)
		{
			SqlParameter[] array = new SqlParameter[4];
			array[0] = new SqlParameter("@ShopName", DbType.String);
			if (ShopName == null)
			{
				array[0].Value = DBNull.Value;
			}
			else
			{
				array[0].Value = ShopName;
			}
			array[1] = new SqlParameter("@ShopChildid", SqlDbType.Int);
			array[1].Value = ShopChildID;
			array[2] = new SqlParameter("@F_ShopClassID", SqlDbType.Int);
			array[2].Value = F_ShopClassID;
			array[3] = new SqlParameter("@F_UserID", SqlDbType.Int);
			array[3].Value = F_UserID;
			return this.conn.GetDataTable("PR_GetFavShopByShopNameShopChildFPCUserID", array);
		}
		public DataTable GetFavProByUpdtPNamePEdtFPCUserID(int F_Update, string ProductName, int ProductEndDate, int F_ProductClassID, int F_UserID)
		{
			SqlParameter[] array = new SqlParameter[5];
			array[0] = new SqlParameter("@F_Update", SqlDbType.Int);
			array[0].Value = F_Update;
			array[1] = new SqlParameter("@ProductName", SqlDbType.NVarChar);
			if (ProductName == null)
			{
				array[1].Value = DBNull.Value;
			}
			else
			{
				array[1].Value = ProductName;
			}
			array[2] = new SqlParameter("@ProductEndDate", SqlDbType.Int);
			array[2].Value = ProductEndDate;
			array[3] = new SqlParameter("@F_ProductClassID", SqlDbType.Int);
			array[3].Value = F_ProductClassID;
			array[4] = new SqlParameter("@F_UserID", SqlDbType.Int);
			array[4].Value = F_UserID;
			return this.conn.GetDataTable("PR_GetFavProByUpdtPNamePEdtFPCUserID", array);
		}
		public DataTable GetFavKeyWordsBySearchNameUserID(string F_SearchName, int UserID)
		{
			SqlParameter[] array = new SqlParameter[2];
			array[0] = new SqlParameter("@F_SearchName", DbType.String);
			array[0].Value = F_SearchName;
			array[1] = new SqlParameter("@UserID", SqlDbType.Int);
			array[1].Value = UserID;
			return this.conn.GetDataTable("PR_GetFavKeyWordsBySearchNameUserID", array);
		}
		public void DeleteFav(int F_ID)
		{
			this.conn.Execute("DELETE [HLShop_MyFavourite] WHERE  ([F_ID] = " + F_ID + ")");
		}
		public void UpdateFva(int F_ProductID, int F_ShopID, DateTime F_Update, int F_Type, string F_SearchName, string F_SearchContens, int F_ProductClassID, int F_ShopClassID, string F_Remark, int F_ID)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@F_ProductID", DbType.Int32, F_ProductID),
				this.conn.CreateParameter("@F_ShopID", DbType.Int32, F_ShopID),
				this.conn.CreateParameter("@F_Update", DbType.DateTime, F_Update),
				this.conn.CreateParameter("@F_Type", DbType.Int32, F_Type),
				this.conn.CreateParameter("@F_SearchName", DbType.String, F_SearchName),
				this.conn.CreateParameter("@F_SearchContens", DbType.String, F_SearchContens),
				this.conn.CreateParameter("@F_ProductClassID", DbType.Int32, F_ProductClassID),
				this.conn.CreateParameter("@F_ShopClassID", DbType.Int32, F_ShopClassID),
				this.conn.CreateParameter("@F_Remark", DbType.String, F_Remark),
				this.conn.CreateParameter("@F_ID", DbType.Int32, F_ID)
			};
			this.conn.Execute("UPDATE [HLShop_MyFavourite] SET  [F_ProductID] = @F_ProductID, [F_ShopID] = @F_ShopID, [F_Update] = @F_Update, [F_Type] = @F_Type, [F_SearchName] = @F_SearchName, [F_SearchContens] = @F_SearchContens, [F_ProductClassID] = @F_ProductClassID, [F_ShopClassID] = @F_ShopClassID,F_Remark=@F_Remark WHERE [F_ID] = @F_ID", parameters);
		}
		public void MoveFProductClass(int F_ProductClassID, string ArrayF_ID)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@F_ProductClassID", DbType.Int32, F_ProductClassID),
				this.conn.CreateParameter("@ArrayF_ID", DbType.String, ArrayF_ID)
			};
			this.conn.Execute("UPDATE [HLShop_MyFavourite] SET  F_ProductClassID =@F_ProductClassID where F_ID in (SELECT * FROM fn_Split(@ArrayF_ID,','))", parameters);
		}
		public void MoveFShopClass(int F_ShopClassID, string ArrayF_ID)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@F_ShopClassID", DbType.Int32, F_ShopClassID),
				this.conn.CreateParameter("@ArrayF_ID", DbType.String, ArrayF_ID)
			};
			this.conn.Execute("UPDATE [HLShop_MyFavourite] SET  F_ShopClassID =@F_ShopClassID where F_ID in (SELECT * FROM fn_Split(@ArrayF_ID,','))", parameters);
		}
		public int GetAllProductCount(int F_UserID)
		{
			return this.conn.ExecuteCount("SELECT count(F_ID) FROM HLShop_MyFavourite where F_UserID=" + F_UserID + " and F_Type=0");
		}
		public int GetProductCountByClassID(int F_UserID, int F_ProductClassID)
		{
			return this.conn.ExecuteCount(string.Concat(new object[]
			{
				"SELECT COUNT(*) FROM HLShop_MyFavourite WHERE (F_UserID = ",
				F_UserID,
				") AND (F_ProductClassID = ",
				F_ProductClassID,
				") AND (F_Type = 0)"
			}));
		}
		public int GetAllShopCount(int F_UserID)
		{
			return this.conn.ExecuteCount("SELECT count(F_ID)   as  allcount FROM HLShop_MyFavourite where F_UserID=" + F_UserID + " and F_type=1");
		}
		public int GetShopCountByClassID(int F_UserID, int F_ShopClassID)
		{
			return this.conn.ExecuteCount(string.Concat(new object[]
			{
				"SELECT  COUNT(*) FROM HLShop_MyFavourite WHERE  F_USERID=",
				F_UserID,
				" AND F_ShopClassID=",
				F_ShopClassID,
				" and F_Type=1"
			}));
		}
		public bool DeleteMyFavourite(string ArrayID)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@ArrayF_ID", DbType.String, ArrayID);
			int num = this.conn.Execute("DELETE FROM [HLShop_MyFavourite] WHERE [F_ID]  in  (SELECT * FROM fn_Split(@ArrayF_ID,','))", new IDbDataParameter[]
			{
				dbDataParameter
			});
			return num > 0;
		}
		public DataTable GetFAVByID(int F_ID)
		{
			return this.conn.GetDataTable("SELECT * FROM HLShop_MyFavourite WHERE (F_ID = " + F_ID + ")");
		}
		public DataRow GetFavShopByF_ID(int F_ID)
		{
			DataTable dataTable = this.conn.GetDataTable("SELECT * FROM HLShop_MyFavourite INNER JOIN  HLShop_Shop ON HLShop_MyFavourite.F_ShopID = HLShop_Shop.ShopID INNER JOIN HLShop_Class ON HLShop_Shop.ShopCategoryID = HLShop_Class.ClassID INNER JOIN HL_User ON HLShop_Shop.ShopOwnerID = HL_User.UserID Inner Join HL_UserInfo On HL_UserInfo.UserID=HLShop_Shop.ShopOwnerID WHERE (HLShop_MyFavourite.F_Type = 1) AND (HLShop_MyFavourite.F_ID = " + F_ID + ")");
			return dataTable.Rows[0];
		}
		public DataRow GetFavProByF_ID(int F_ID)
		{
			DataTable dataTable = this.conn.GetDataTable("SELECT * ,CASE WHEN ProductType =1 THEN StandPrice  when (ProductType=3 and TeamNum=1)  then TeamPrice1 when(ProductType=3 and TeamNum=2) then TeamPrice2 when(ProductType=3 and TeamNum=3) then TeamPrice3 when(ProductType=3 and TeamNum=4) then TeamPrice4 when(ProductType=3 and TeamNum=5) then TeamPrice5  ELSE AuctionStartPrice END AS ProductPrice, DATEDIFF(s, GETDATE(), HLShop_Product.EndDate) AS LeftTime, HLShop_Product.ProductSmallImageUrl, HLShop_MyFavourite.F_UserID FROM HLShop_MyFavourite INNER JOIN HLShop_Product ON HLShop_MyFavourite.F_ProductID = HLShop_Product.ProductID INNER JOIN HL_User ON HLShop_Product.SalerID = HL_User.UserID WHERE (HLShop_MyFavourite.F_Type = 0) AND (HLShop_MyFavourite.F_ID = " + F_ID + ")");
			return dataTable.Rows[0];
		}
		public int InsertFav(int? F_UserID, int? F_ProductID, int? F_ShopID, DateTime? F_Update, int? F_Type, string F_SearchName, string F_SearchContens, int? F_ProductClassID, int? F_ShopClassID, string F_Remark)
		{
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@RETURN_VALUE", SqlDbType.Int, 4, ParameterDirection.ReturnValue, 10, 0, null, DataRowVersion.Current, false, null, "", "", ""),
				new SqlParameter("@F_UserID", SqlDbType.Int, 4, ParameterDirection.Input, 10, 0, null, DataRowVersion.Current, false, null, "", "", ""),
				new SqlParameter("@F_ProductID", SqlDbType.Int, 4, ParameterDirection.Input, 10, 0, null, DataRowVersion.Current, false, null, "", "", ""),
				new SqlParameter("@F_ShopID", SqlDbType.Int, 4, ParameterDirection.Input, 10, 0, null, DataRowVersion.Current, false, null, "", "", ""),
				new SqlParameter("@F_Update", SqlDbType.DateTime, 8, ParameterDirection.Input, 23, 3, null, DataRowVersion.Current, false, null, "", "", ""),
				new SqlParameter("@F_Type", SqlDbType.Int, 4, ParameterDirection.Input, 10, 0, null, DataRowVersion.Current, false, null, "", "", ""),
				new SqlParameter("@F_SearchName", SqlDbType.VarChar, 50, ParameterDirection.Input, 0, 0, null, DataRowVersion.Current, false, null, "", "", ""),
				new SqlParameter("@F_SearchContens", SqlDbType.VarChar, 500, ParameterDirection.Input, 0, 0, null, DataRowVersion.Current, false, null, "", "", ""),
				new SqlParameter("@F_ProductClassID", SqlDbType.Int, 4, ParameterDirection.Input, 10, 0, null, DataRowVersion.Current, false, null, "", "", ""),
				new SqlParameter("@F_ShopClassID", SqlDbType.Int, 4, ParameterDirection.Input, 10, 0, null, DataRowVersion.Current, false, null, "", "", ""),
				new SqlParameter("@F_Remark", SqlDbType.Text, 2147483647, ParameterDirection.Input, 0, 0, null, DataRowVersion.Current, false, null, "", "", "")
			};
			if (F_UserID.HasValue)
			{
				array[1].Value = F_UserID.Value;
			}
			else
			{
				array[1].Value = DBNull.Value;
			}
			if (F_ProductID.HasValue)
			{
				array[2].Value = F_ProductID.Value;
			}
			else
			{
				array[2].Value = DBNull.Value;
			}
			if (F_ShopID.HasValue)
			{
				array[3].Value = F_ShopID.Value;
			}
			else
			{
				array[3].Value = DBNull.Value;
			}
			if (F_Update.HasValue)
			{
				array[4].Value = F_Update.Value;
			}
			else
			{
				array[4].Value = DBNull.Value;
			}
			if (F_Type.HasValue)
			{
				array[5].Value = F_Type.Value;
			}
			else
			{
				array[5].Value = DBNull.Value;
			}
			if (F_SearchName == null)
			{
				array[6].Value = DBNull.Value;
			}
			else
			{
				array[6].Value = F_SearchName;
			}
			if (F_SearchContens == null)
			{
				array[7].Value = DBNull.Value;
			}
			else
			{
				array[7].Value = F_SearchContens;
			}
			if (F_ProductClassID.HasValue)
			{
				array[8].Value = F_ProductClassID.Value;
			}
			else
			{
				array[8].Value = DBNull.Value;
			}
			if (F_ShopClassID.HasValue)
			{
				array[9].Value = F_ShopClassID.Value;
			}
			else
			{
				array[9].Value = DBNull.Value;
			}
			if (F_Remark == null)
			{
				array[10].Value = DBNull.Value;
			}
			else
			{
				array[10].Value = F_Remark;
			}
			return Convert.ToInt32(this.conn.GetDataTable("PR_InsertMyFavourite", array).Rows[0]["F_ID"]);
		}
	}
}
